package servlets;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dataTypes.*;

@SuppressWarnings("serial")
public class businessLogIn extends HttpServlet {

	public businessLogIn() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		try {
			response.setContentType("text/html");
			

			//response.sendRedirect("/adminlogin.html");

			// access business DB to confirm business exists and password is valid 
			// then present 2 options: enter new deal/manage current deal 


		} catch (Exception e) { 
			e.printStackTrace();
		}		

	}

	@SuppressWarnings("static-access")
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("text/html");
			PrintWriter pw = response.getWriter();


			String username = request.getParameter("username");
			String  password=request.getParameter("password").trim();

			long ret = appManager.getInstance().businessLog(username, password);
			// use ret to redirect/alert
			
			//just checking if it works

			
			if (ret>0){
				response.sendRedirect("/adminchose.html?bId="+ret);

			}
			else{
				
				response.sendRedirect("/adminlogin.html?bId=wrong");
			}
			//response.sendRedirect("/adminlogin.html");
			// access business DB to confirm business exists and password is valid 
			// then present 2 options: enter new deal/manage current deal 


		} catch (Exception e) { 
			e.printStackTrace();
		}		

	}

}
